﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data.SQLite;

namespace DotNet.Sqlite
{
    /// <summary>
    /// 数据库操作逻辑类
    /// </summary>
    public class DBBLL
    {
        /// <summary>
        /// 获得数据库存储文件夹 『包含结束符\』
        /// </summary>
        /// <returns></returns>
        public static string GetDBFolder()
        {
            return System.AppDomain.CurrentDomain.BaseDirectory;
        }

        /// <summary>
        /// 获得数据库名称
        /// </summary>
        /// <returns></returns>
        public static string GetDBFileName()
        {
            return "mySqlite.db";
        }

        public static string GetDbConStr()
        {
            return String.Format("Data Source={0};Pooling=False",GetDBFolder() + GetDBFileName());;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static bool TestDbConnect()
        {
            string str = GetDbConStr();
            if (!File.Exists(str))
            {
                SQLiteConnection.CreateFile(GetDBFolder() + GetDBFileName());
            }

            if (SQLiteHelper.TestMyDBConnect(GetDbConStr()))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
